<?php
/**
 * Created by PhpStorm.
 * User: wchuang
 * Date: 2016/8/26
 * Time: 15:58
 */

namespace common\queue;


use common\services\UserService;

class UserJob extends Job
{
	public function setUp()
	{
		// ... Set up environment for this job
	}

	public function perform()
	{

		if(isset($this->args['action'],$this->args['args'])){
			$action = $this->args['action'];
			$args = $this->args['args'];

			if(in_array($action,get_class_methods(__CLASS__))){
				$res = $this->$action($args);
				if($res){
					fwrite(STDOUT, '===========' . __CLASS__ . '->' . $action . 'execute success==========='. "\n");
				}else{
					fwrite(STDOUT, '===========' . __CLASS__ . '->' . $action . 'execute fail==========='. "\n");
				}
			}else{
				fwrite(STDOUT, '----------action is not found--------' . "\n");
			}
		}else{
			fwrite(STDOUT, '----------argument is error--------' . "\n");
		}


	}

	public function tearDown()
	{
		// ... Remove environment for this job
	}

	public function createUser(){
		$res =  (new UserService())->userCreate();

		if($res){
			fwrite(STDOUT, '===========create user success==========='. "\n");
		}else{
			fwrite(STDOUT, '===========create user fail==========='. "\n");
		}
		return true;
	}
}